package main

import . "local/algorithm/util"

func remove(head *ListNode, val int) *ListNode {
	dn := &ListNode{Next: head}
	prev := dn
	for head != nil {
		if head.Val == val {
			prev.Next = head.Next
			head = head.Next
		} else {
			prev = head
			head = head.Next
		}
	}
	return dn.Next
}

func main() {
	list := GenerateLinkedList([]int{1, 2, 6, 3, 4, 5, 6})
	PrintLinkedList(remove(list, 6))
}
